import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void initArrayOrder(int[]array) {
        for (int i = 0; i < array.length ; i++) {
            //array[i]=i;
           // 逆序
            array[i]=array.length-i;
        }
    }
    public static void initArrayNotOrder(int[]array) {
        Random random=new Random();
        for (int i = 0; i < array.length ; i++) {
            array[i]=random.nextInt(100000);
            // array[i]=array.length-i;
        }
    }

    /**
     * 堆排序
     * @param array
     */
    public static void testHeapSort(int[]array) {
        //堆排序
        array=Arrays.copyOf(array,array.length);
        //有序
        //initArrayOrder(array);
        //无序
        initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        MySort.HeapSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("堆排序"+(endTime-startTime));

    }
    /**
     * 两端选择排序
     * @param array
     */
    public static void testTwoSelectSortSort(int []array) {
        array=Arrays.copyOf(array,array.length);
        //有序
        //initArrayOrder(array);
        //无序
        initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        MySort.twoSelectSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("两端选择排序"+(endTime-startTime));

    }
    //选择排序
    public static void testSelectSort(int []array) {
        array=Arrays.copyOf(array,array.length);
        //有序
        //initArrayOrder(array);
        //无序
        initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        MySort.selectSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("选择排序"+(endTime-startTime));

    }
    //插入排序
    public static void testInsertSort(int []array) {
        array=Arrays.copyOf(array,array.length);
        //有序
        //initArrayOrder(array);
        //无序
        initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        MySort.insertSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("插入排序"+(endTime-startTime));

    }
    public static void testShellSort(int[]array) {
        //希尔排序
        array=Arrays.copyOf(array,array.length);
        //有序
        //initArrayOrder(array);
        //无序
        initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        MySort.ShellSort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("希尔排序"+(endTime-startTime));
    }

    public static void testQuickSort(int[]array) {
        //快速排序
        array=Arrays.copyOf(array,array.length);
        //有序
        initArrayOrder(array);
        //无序
       // initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        //MySort.quickSort1(array);
       Arrays.sort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("快速排序 无序数组"+(endTime-startTime));
    }

    public static void testMergeSort(int[]array) {
        //快速排序
        array=Arrays.copyOf(array,array.length);
        //有序
        System.out.println("13333342323");
        initArrayOrder(array);
        //无序
        // initArrayNotOrder(array);
        long startTime=System.currentTimeMillis();
        MySort.mergeSort(array);
        //Arrays.sort(array);
        long endTime=System.currentTimeMillis();
        System.out.println("归并排序 无序数组"+(endTime-startTime));
    }
        public static void main1(String[] args) {
        int []array=new int[100000];
/*

        testInsertSort(array);

        testShellSort(array);

        testSelectSort(array);

        testTwoSelectSortSort(array);

        testHeapSort(array);
*/

        testQuickSort(array);
    }
    public static void main(String[] args) {
        int []array={65,31,5,62,71,6,546,21};
        int []array1={9,8,7,6,5,4,3,2,1};
        MySort.mergeSort(array);
        System.out.println(Arrays.toString(array));
    }
}
